<template>
  <div class="leftCommonWrapper" :class="{ isShrink: state.isShrink }">
      <Rainfall />
      <WarningInfo />
      <ReservoirMonitoring />
    <slot></slot>
    <div class="shrinkBtn" @click="handleClickShrink">
      <MenuFoldOutlined :rotate="state.iconRotate" />
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { reactive, watch } from 'vue';
  import { MenuFoldOutlined } from '@ant-design/icons-vue';
  import Rainfall from './Rainfall';
  import WarningInfo from './WarningInfo';
  import ReservoirMonitoring from './ReservoirMonitoring';

  defineOptions({ name: 'LeftCommon' });

  const state = reactive({
    isShrink: false,
    iconRotate: 0,
  });

  const props = defineProps({
    isCollapse: { type: Boolean },
  });

  // 一键收起侧边栏
  watch(
    () => props.isCollapse,
    (val) => {
      state.isShrink = val;
      state.iconRotate = val ? 180 : 0;
    }
  );

  const handleClickShrink = () => {
    state.isShrink = !state.isShrink;
    state.iconRotate = state.isShrink ? 180 : 0;
  };
</script>

<style lang="less" rel="stylesheet/less" scoped>
  .leftCommonWrapper {
    width: 430px;
    height: calc(100% - 26px);
    background: linear-gradient(90deg, rgba(255, 255, 255, 1) 60%, rgba(255, 255, 255, 0.9) 88%, rgba(255, 255, 255, 0.2) 100%);
    position: absolute;
    top: 0;
    left: 0;
    z-index: 200;
    transition: all 0.5s;
    transform: translateX(0px);
    padding: 10px 16px 16px 16px;

    display: grid;
    grid-template-rows: minmax(260px, 31%) minmax(230px, 32%) minmax(260px, 36%);
    grid-row-gap: 10px;
    .contents {
      width: 100%;
      height: 100%;
      overflow: hidden;
      overflow-y: auto;
      // display: grid;
      grid-template-rows: minmax(280px, 32%) minmax(290px, 34%) minmax(290px, 34%);
      grid-row-gap: 4px;
      display: flex;
      flex-direction: column;
      &::-webkit-scrollbar {
        width: 0;
        height: 0;
      }
    }
    .shrinkBtn {
      width: 28px;
      height: 28px;
      background: rgba(204, 226, 243, 0.8);
      color: #60aded;
      border-radius: 4px;
      position: absolute;
      top: 10px;
      left: 430px;
      z-index: 1000;
      font-size: 18px;
      cursor: pointer;
      display: flex;
      align-items: center;
      justify-content: center;
      opacity: 0.6;
      transition: all 0.5s;
      transform: translateX(0px);
      backdrop-filter: blur(8px);
      -webkit-backdrop-filter: blur(8px);
      &:hover {
        background: rgba(204, 226, 243, 1);
        opacity: 1;
      }
    }
  }
  .isShrink {
    transform: translateX(-430px);
  }
</style>
